<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
<meta name="viewport"
      content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">

    <meta name="author" content="kissdata">


    <meta name="subtitle" content="人生笔记">


    <meta name="description" content="南邮计算机学院2021毕业生王鹏的介绍，cs软件工程专业">


    <meta name="keywords" content="wangpeng 王鹏 南邮 南京">


<title>💥 | Ubuntu 编译openwrt | 王鹏的小岛</title>



    <link rel="icon" href="/myIcon.ico">




    <!-- stylesheets list from _config.yml -->
    
    <link rel="stylesheet" href="/css/style.css">
    



    <!-- scripts list from _config.yml -->
    
    <script src="/js/script.js"></script>
    
    <script src="/js/tocbot.min.js"></script>
    



    
    
        <!-- MathJax配置，可通过单美元符号书写行内公式等 -->
<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
    "HTML-CSS": {
        preferredFont: "TeX",
        availableFonts: ["STIX","TeX"],
        linebreaks: { automatic:true },
        EqnChunk: (MathJax.Hub.Browser.isMobile ? 10 : 50)
    },
    tex2jax: {
        inlineMath: [ ["$", "$"], ["\\(","\\)"] ],
        processEscapes: true,
        ignoreClass: "tex2jax_ignore|dno",
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
    },
    TeX: {
        equationNumbers: { autoNumber: "AMS" },
        noUndefined: { attributes: { mathcolor: "red", mathbackground: "#FFEEEE", mathsize: "90%" } },
        Macros: { href: "{}" }
    },
    messageStyle: "none"
    });
</script>
<!-- 给MathJax元素添加has-jax class -->
<script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for(i=0; i < all.length; i += 1) {
            all[i].SourceElement().parentNode.className += ' has-jax';
        }
    });
</script>
<!-- 通过连接CDN加载MathJax的js代码 -->
<script type="text/javascript" async
        src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML">
</script>


    


<meta name="generator" content="Hexo 7.0.0"></head>

<body>
    <script>
        // this function is used to check current theme before page loaded.
        (() => {
            const currentTheme = window.localStorage && window.localStorage.getItem('theme') || '';
            const isDark = currentTheme === 'dark';
            const pagebody = document.getElementsByTagName('body')[0]
            if (isDark) {
                pagebody.classList.add('dark-theme');
                // mobile
                document.getElementById("mobile-toggle-theme").innerText = "· Dark"
            } else {
                pagebody.classList.remove('dark-theme');
                // mobile
                document.getElementById("mobile-toggle-theme").innerText = "· Light"
            }
        })();
    </script>

    <div class="wrapper">
        <header>
    <nav class="navbar">
        <div class="container">
            <div class="navbar-header header-logo"><a href="/">侠之大者</a></div>
            <div class="menu navbar-right">
                
                    <a class="menu-item" href="/update/mystate">Career</a>
                
                    <a class="menu-item" href="/category">Legend</a>
                
                    <a class="menu-item" href="/about">Me</a>
                
                <input id="switch_default" type="checkbox" class="switch_default">
                <label for="switch_default" class="toggleBtn"></label>
            </div>
        </div>
    </nav>

    
    <nav class="navbar-mobile" id="nav-mobile">
        <div class="container">
            <div class="navbar-header">
                <div>
                    <a href="/">侠之大者</a><a id="mobile-toggle-theme">·&nbsp;Light</a>
                </div>
                <div class="menu-toggle" onclick="mobileBtn()">&#9776; Menu</div>
            </div>
            <div class="menu" id="mobile-menu">
                
                    <a class="menu-item" href="/update/mystate">Career</a>
                
                    <a class="menu-item" href="/category">Legend</a>
                
                    <a class="menu-item" href="/about">Me</a>
                
            </div>
        </div>
    </nav>

</header>
<script>
    var mobileBtn = function f() {
        var toggleMenu = document.getElementsByClassName("menu-toggle")[0];
        var mobileMenu = document.getElementById("mobile-menu");
        if(toggleMenu.classList.contains("active")){
           toggleMenu.classList.remove("active")
            mobileMenu.classList.remove("active")
        }else{
            toggleMenu.classList.add("active")
            mobileMenu.classList.add("active")
        }
    }
</script>
            <div class="main">
                <div class="container">
    
    

    
    <article class="post-wrap">
        <header class="post-header">
            <h1 class="post-title">💥 | Ubuntu 编译openwrt</h1>
            
                <div class="post-meta">
                    
                        Author: <a itemprop="author" rel="author" href="/">kissdata</a>
                    

                    
                        <span class="post-time">
                        Date: <a href="#">Dec 14, 2023&nbsp;&nbsp;0:00</a>
                        </span>
                    
                    
                        <span class="post-category">
                    Category:
                            
                                <a href="/categories/Deploy/">Deploy</a>
                            
                        </span>
                    
                </div>
            
        </header>

        <div class="post-content">
            <p>openwrt，嵌入式方面的小操作系统。需要在 Linux 上交叉编译，然后烧进开发板。网上的教程都是基于 <code>16.04</code> 多，新系统有一堆问题。</p>
<p>环境：Ubuntu + gcc</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">  tool       version</span><br><span class="line"># -- -- -- | -- -- -- #</span><br><span class="line">· GCC         11.3</span><br><span class="line">· python2     2.7</span><br><span class="line">· python3     3.10</span><br><span class="line">· openwrt     23.05</span><br></pre></td></tr></table></figure>

<p>openwrt 中最好安装上的工具：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">file, gwak, grep, iconv, ldconfig, </span><br><span class="line">lscpu, lsof, more, sed, </span><br><span class="line">tar, tree, whereis, xxd</span><br></pre></td></tr></table></figure>

<p>编译安装 libiconv 和 gettext ，两者有蛋鸡关系，谁先安装的就要安装两次，比如安装 libiconv 完成后安装 gettext ，然后还要重装一下 libiconv，就是这么搞头。 </p>
<p>package 目录都是存放要下载的东西，结构和 make menu 的形式一致，qt通过 feed增加，自然在 feeds 子目录里。 修改 libqt 的 makefile</p>
<figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line"><span class="keyword">define</span> Package/qt5/Default</span><br><span class="line">  SECTION:=libs</span><br><span class="line">  CATEGORY:=Libraries</span><br><span class="line">  SUBMENU:=Qt5</span><br><span class="line">  TITLE:=qt5</span><br><span class="line">  URL:=http://qt-project.org</span><br><span class="line">  DEPENDS:=+librt +zlib +libstdcpp +libpcre16 +libpcre2-16 +glib2 +libpthread \</span><br><span class="line">           +libudev +libatomic +libmysqlclient @!LINUX_2_6</span><br><span class="line"><span class="keyword">endef</span></span><br></pre></td></tr></table></figure>

<p>其实就是加一句 <code>+libpcre2-16</code> </p>
<p><code>make menuconfig</code> 提供配置。在选目标镜像的时候，<code>squashfs</code> 是必选的，另外要把 <code>tar.gz</code> 选上：</p>
<p><img src="/../image/res_ubuntu/openwrt_make0.png"></p>
<p>不然只是打出 <code>.bin</code> 固件后期想用 qemu 模拟运行的话，qemu 不能识别 bin 文件。</p>
<p>编译中，会先做出交叉工具链.</p>
<p><img src="/../image/res_ubuntu/openwrt_make2.png"></p>
<p>存放在 <code>../build_dir/</code> 目录，注意里面有两个名字是序列格式取名的，看起来大差不差，用途不一样。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">host/</span><br><span class="line">hostpkg/</span><br><span class="line">target-mipsel_24kc_musl/</span><br><span class="line">toolchain-mipsel_24kc_gcc-8.4.0_musl/</span><br></pre></td></tr></table></figure>

<p>不同的系统链条不一样，主要是 gcc 的版本，但是这个 gcc的版本和本地不一样。</p>
<ul>
<li>ubuntu20 gcc 9.4: <code>toolchain-mipsel_24kc_gcc-8.4.0_musl/</code></li>
<li>ubuntu22 gcc 11.4: <code>toolchain-mipsel_24kc_gcc-12.3.0_musl/</code></li>
</ul>
<p>固件</p>
<p>缺少 <code>execinfo.h</code> 头文件。因为 openwrt 默认采用 musl 系列编译，不带这个文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">../qt_main.c:89:10: fatal error: execinfo.h: No such file or directory</span><br></pre></td></tr></table></figure>

<p>（提示是如果不带库软件就不能跑，那么程序也不能运行在 openwrt 上）。</p>

        </div>

        
            <section class="post-copyright">
                
                
                
                
                     <p class="copyright-item">
                         <span>Slogan:</span>
                         <span>人生三大错觉：我躲得过去，我能反杀，是不是<strong>喜欢我?</strong></span>
                     </p>
                

            </section>
        
        <section class="post-tags">
            <div>
            </div>
            <div>
                <a href="javascript:window.history.back();">back</a>
                <span>· </span>
                <a href="/">home</a>
            </div>
        </section>
        <section class="post-nav">
            
                <a class="prev" rel="prev" href="/2024/01-1/tool_gcc/">⛵ Linux 更新GCC</a>
            
            
            <a class="next" rel="next" href="/2023/12-8/work_ubuntu/">🆗 搭建工作用的 Ubuntu</a>
            
        </section>


    </article>
</div>

            </div>
            <footer id="footer" class="footer">
    <div class="copyright">
        <span>187-9597-5517 &nbsp; 王鹏 @ <a href="https://cs.njupt.edu.cn/" target="_blank">njupt</a</span>
    </div>
</footer>

    </div>
</body>

</html>